# -*- coding: utf-8 -*-
# @Time : 2024/5/6 10:41
# @Author : Zxg
# @Email : 1473858993@qq.com
# @File : checksheetpage.py
# @Project : Luckin_Finance_UI
from time import sleep
import pyautogui
from common.basepage import BasePage
from common.webdriver import driver
from selenium.webdriver.common.by import By
from utils.mysql_util import mysql_method


# 报账单流程
class Check_Sheet_Page(BasePage):
    # 入口iframe定位
    iframe_one = 'name9012030000'
    # 对公付款测试定位
    payments_test_public = By.XPATH, '//*[@id="app"]/div/div[2]/div[2]/div[5]/div/div/div[2]/div[4]'
    # 对公付款测试iframe定位
    iframe_two = '/132/reimbursement-edit?businessId=1224&parentName=%E5%AF%B9%E5%85%AC%E4%BB%98%E6%AC%BE&kidName=%E5%AF%B9%E5%85%AC%E4%BB%98%E6%AC%BE%E6%B5%8B%E8%AF%95&popType=add&tabTitle=%E6%8A%A5%E8%B4%A6%E5%8D%95%E7%94%B3%E8%AF%B7-%E5%AF%B9%E5%85%AC%E4%BB%98%E6%AC%BE%E6%B5%8B%E8%AF%95&isPathComponent=false&manyTab=true&fromRouteName=name9012030000'
    # 选择所属岗位类别
    jobcategory = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[1]/div[2]/form/div[1]/div[5]/div/div/div/div'
    # 选择总部
    select_head_office = By.CLASS_NAME, 'el-select-dropdown__item hover'
    # 选择流程类型
    process_type = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[1]/div[2]/form/div[1]/div[10]/div/div/div/div'
    # 选择正常
    select_normal = By.XPATH, '/html/body/div[3]/div[1]/div[1]/ul/li[1]'
    # 供应商定位
    supplier = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[1]/div[2]/form/div[1]/div[7]/div/div/div/input'
    # 供应商内部iframe定位
    iframe_three = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[1]/div[2]/div/div/div[2]/div/iframe'
    # 供应商名称定位
    supplier_name = By.XPATH, '/html/body/div/div/section/header/div/div/label[2]/div/input'
    # 搜索按钮定位
    serch_button = By.XPATH, '/html/body/div/div/section/header/div/div/div/button[1]'
    # 点击选择供应商
    select_supplier = By.XPATH, '/html/body/div/div/section/main/div[1]/div[3]/table/tbody/tr/td[4]/div/div/a/span'
    # 选择收款方账号
    account_number = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[2]/div[2]/form/div[1]/div[4]/div/div/div[1]/input'
    # 收款方账号iframe定位
    iframe_fore = By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div/div[2]/div/iframe'
    # 选择收款方账号
    number = By.XPATH, '/html/body/div/div/section/main/div[1]/div[3]/table/tbody/tr[1]/td[6]/div/div/a/span'

    # 点击下一步
    next = By.XPATH, '/html/body/div/div/div[1]/div[1]/div[2]/button[4]/span'

    def checksheetpage(self):
        # 打开初始页面
        driver.get('https://fiwebtest03.lkcoffee.com/default/132/welcome/Welcome')
        # 切换iframe
        self.switch_to_frame(self.iframe_one)
        # 点击对公付款测试
        self.click(self.payments_test_public)
        # 退出iframe
        self.exit_frame()
        sleep(10)
        # 切换最新窗口
        self.switch_win(-1)
        # 切换对公付款iframe窗口
        self.switch_to_frame(self.iframe_two)
        # 点击所属岗位类别下拉列表
        self.click(self.jobcategory)
        # 点击选择总部
        ele_one = self.find_wait(self.select_head_office, 20)
        self.click(ele_one)
        # 点击流程类型下拉列表
        self.click(self.process_type)
        # 选择正常
        self.click(self.select_normal)
        # 点击选择供应商
        self.click(self.supplier)
        # 切换选择供应商iframe
        iframe_ele = self.find_wait(self.iframe_three, 20)
        self.switch_to_frame(iframe_ele)
        # 输入名称
        self.send_key(self.supplier_name, '刘艳华1')
        # 点击搜索
        self.click(self.serch_button)
        # 选中供应商
        self.click(self.select_supplier)
        # 退出iframe
        self.exit_frame()
        # 进入对公付款测试iframe
        self.switch_to_frame(self.iframe_two)
        # 点击收款方账号
        self.click(self.account_number)
        # 切入选择收款方账号iframe
        iframe_ele_two = self.find_wait(self.iframe_fore, 20)
        self.switch_to_frame(iframe_ele_two)
        # 选中收款方账号
        self.click(self.number)
        # 退出iframe
        self.exit_frame()
        # 切换对公付款iframe窗口
        self.switch_to_frame(self.iframe_two)
        # 点击下一步
        self.click(self.next)
